<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>计算字符串中出现次数最多的字符以及出现最多的次数？</title>
</head>

<body>
</body>
<script>
    // 计算字符串中出现次数最多的字符以及出现最多的次数？
    const str = "aaabbbbccfsdssss";
    let obj = {};
    for (let i = 0; i < str.length; i++) {
        if (!obj[str[i]]) {
            obj[str[i]] = 1;
        } else {
            obj[str[i]] = obj[str[i]] + 1;
        }
    }
    console.log(obj);

    // 从对象中找出出现次数做多的字符和次数值
    let max = 0;
    let charStr = ''
    for (let i in obj) {
        if (obj[i] > max) {
            max = obj[i];
            charStr = i;
        }
    }
    console.log(charStr, max);
</script>

</html>